﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Incominginformations;

namespace MyMES.Writer.API.Application.CommendHandlers.Incominginformations
{
    public class UpdataArrivalnoticeStaturCommendHandlers : IRequestHandler<UpdataArrivalnoticeStaturCommends, APIResult<Arrivalnotice>>
    {
        private readonly IBaseRepository<Arrivalnotice> arrivalnoticeRepository;
        private readonly IMapper mapper;
     
        /// <summary>
        /// 构成函数注入
        /// </summary>
        /// <param name="arrivalnoticeRepository"></param>
        /// <param name="mapper"></param>
        public UpdataArrivalnoticeStaturCommendHandlers(IBaseRepository<Arrivalnotice> arrivalnoticeRepository, IMapper mapper)
        {
            this.arrivalnoticeRepository = arrivalnoticeRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 修改到货通知单状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Arrivalnotice>> Handle(UpdataArrivalnoticeStaturCommends request, CancellationToken cancellationToken)
        {
            var result = new APIResult<Arrivalnotice>();


         
                string sql = $"UPDATE Incominginformation  SET NoticePurchase = 3  WHERE StorageId = @StorageId   ";
            // 4. 明确传递参数
            var enter = mapper.Map<Incominginformation>(request);

            // 调用仓储层
            await arrivalnoticeRepository.Updatestatus(enter, sql);
                result.Code = APIEnum.修改成功;
                result.Msg = "状态更新成功";
                return result;
     




        }
    }
}
